import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;

import javax.swing.JPanel;
import javax.swing.JOptionPane;

/**
 *
 * @author jolynn
 */
public class Add extends javax.swing.JPanel {
	JPanel mainPanel;
	Connection con;
	
	private String timeType = null, reminder = null, rHour = null, rMin = null, rTimeType = null;
    private String rDate = null, rMonth = null, rYear = null, hour = null, min = null;
    
    static String addEntryDate = null;
    boolean choice = true;
    
    public Add(JPanel panel) {
    	mainPanel = panel;
    	
    	try {
            con = DriverManager.getConnection("jdbc:derby://localhost:1527/user", "user", "user");
            System.out.println("DB connected from AddEntry");
            
        } catch (SQLException ex) {
        	//Logger.getLogger(ConnectingDatabase.class.getName()).log(Level.SEVERE, null, ex);
        	System.out.println(ex.getMessage());
        }
        
        initComponents();
        
        backButton.addActionListener(new PanelSwitchToEntryMenu());
    }
    
    @SuppressWarnings("unchecked")
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        addTitle = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        titleTextField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        hourComboBox = new javax.swing.JComboBox();
        minComboBox = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        venueTextField = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        descriptionTextArea = new javax.swing.JTextArea();
        timeTypeComboBox = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        reminderComboBox = new javax.swing.JComboBox();
        rHourComboBox = new javax.swing.JComboBox();
        rMinComboBox = new javax.swing.JComboBox();
        rTimeTypeComboBox = new javax.swing.JComboBox();
        backButton = new javax.swing.JButton();
        saveButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        rDateComboBox = new javax.swing.JComboBox();
        rMonthComboBox = new javax.swing.JComboBox();
        rYearComboBox = new javax.swing.JComboBox();


        jPanel1.setFont(new java.awt.Font("DejaVu Sans", 0, 15));

        addTitle.setFont(new java.awt.Font("DejaVu Sans", 1, 36)); // NOI18N
        addTitle.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        addTitle.setText("ADD ENTRY");

        jLabel2.setFont(new java.awt.Font("DejaVu Sans", 1, 16)); // NOI18N
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText("TITLE :");

        titleTextField.setFont(new java.awt.Font("DejaVu Sans", 0, 16)); // NOI18N

        jLabel3.setFont(new java.awt.Font("DejaVu Sans", 1, 16)); // NOI18N
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel3.setText("TIME :");

        hourComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "HOUR", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" }));
        hourComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hourComboBoxActionPerformed(evt);
            }
        });
        
        minComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "MIN", "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59"}));
        minComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                minComboBoxActionPerformed(evt);
            }
        });
        
        jLabel4.setFont(new java.awt.Font("DejaVu Sans", 1, 16));
        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel4.setText("VENUE :");

        venueTextField.setFont(new java.awt.Font("DejaVu Sans", 0, 16));

        jLabel5.setFont(new java.awt.Font("DejaVu Sans", 1, 16));
        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel5.setText("DESCRIPTION :");

        descriptionTextArea.setColumns(20);
        descriptionTextArea.setFont(new java.awt.Font("DejaVu Sans", 0, 16)); // NOI18N
        descriptionTextArea.setRows(5);
        jScrollPane1.setViewportView(descriptionTextArea);

        timeTypeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "AM", "PM" }));
        timeTypeComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                timeTypeComboBoxActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("DejaVu Sans", 1, 16)); // NOI18N
        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel6.setText("REMINDER :");

        jLabel7.setFont(new java.awt.Font("DejaVu Sans", 1, 16)); // NOI18N
        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel7.setText("REMINDER TIME :");

        reminderComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "YES", "NO" }));
        reminderComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	reminderComboBoxActionPerformed(evt);
            }
        });
        
        rHourComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "HOUR", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" }));
        rHourComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	rHourComboBoxActionPerformed(evt);
            }
        });
        
        rMinComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "MIN", "00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59"}));
        rMinComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	rMinComboBoxActionPerformed(evt);
            }
        });
        
        rTimeTypeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "AM", "PM" }));
        rTimeTypeComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	rTimeTypeComboBoxActionPerformed(evt);
            }
        });
        
        backButton.setText("BACK");
    
        saveButton.setText("SAVE");
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	saveButtonActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("DejaVu Sans", 1, 16)); // NOI18N
        jLabel1.setText("REMINDER DATE :");

        rDateComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "DATE", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
        rDateComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	rDateComboBoxActionPerformed(evt);
            }
        });
        
        rMonthComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "MONTH", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" }));
        rMonthComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	rMonthComboBoxActionPerformed(evt);
            }
        });
        
        rYearComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "YEAR", "2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020", "2021", "2022", "2023", "2024", "2025", "2026", "2027", "2028", "2029", "2030", "2031", "2032", "2033", "2034", "2035", "2036", "2037", "2038", "2039", "2040", "2041", "2041", "2042", "2043", "2044", "2045", "2046", "2047", "2048", "2049", "2050", "2051", "2052", "2053", "2054", "2055", "2056", "2057", "2058", "2059", "2060", "2061", "2062", "2063", "2064", "2065", "2066", "2067", "2068", "2069", "2070", "2071", "2072", "2073", "2074", "2075", "2076", "2077", "2078", "2079", "2080", "2081", "2082", "2083", "2084", "2085", "2086", "2087", "2088", "2089", "2090", "2091", "2092", "2093", "2094", "2095", "2096", "2097", "2098", "2099", "2100", "2101", "2102", "2103", "2104", "2105", "2106", "2107", "2108", "2109", "2110" }));
        rYearComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	rYearComboBoxActionPerformed(evt);
            }
        });
        
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(addTitle, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 638, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 198, Short.MAX_VALUE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 198, Short.MAX_VALUE)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4))
                        .addGap(50, 50, 50)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(titleTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(hourComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(minComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(timeTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(venueTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(backButton, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(saveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(70, 70, 70))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addGap(50, 50, 50)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(rDateComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(rMonthComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(rYearComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(rHourComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(rMinComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(rTimeTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(reminderComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 123, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(44, 44, 44)
                .addComponent(addTitle)
                .addGap(26, 26, 26)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(titleTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(hourComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(minComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(timeTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(venueTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addComponent(jLabel5))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(reminderComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rHourComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(rMinComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rTimeTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(rDateComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rMonthComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rYearComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 69, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(saveButton)
                    .addComponent(backButton))
                .addGap(35, 35, 35))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }
    
    private void hourComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
    	hour = null;
    	hour = (String)hourComboBox.getSelectedItem();
    }
    
    private void minComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
    	min = null;
    	min = (String)minComboBox.getSelectedItem();
    }
    
    private void timeTypeComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
    	timeType = null;
    	timeType = (String)timeTypeComboBox.getSelectedItem();
    	
    }                                                
	
	private void reminderComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
		reminder = null;
		reminder = (String)reminderComboBox.getSelectedItem();
		
		if(reminder.equals("YES")) {
    		rHourComboBox.setEnabled(true);
    		rMinComboBox.setEnabled(true);
    		rTimeTypeComboBox.setEnabled(true);
    		rDateComboBox.setEnabled(true);
    		rMonthComboBox.setEnabled(true);
    		rYearComboBox.setEnabled(true);
    	}
    	else if(reminder.equals("NO")) {
    		rHourComboBox.setEnabled(false);
    		rMinComboBox.setEnabled(false);
    		rTimeTypeComboBox.setEnabled(false);
    		rDateComboBox.setEnabled(false);
    		rMonthComboBox.setEnabled(false);
    		rYearComboBox.setEnabled(false);
    	}
	}
	
	private void rHourComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
		rHour = null;
		rHour = (String)rHourComboBox.getSelectedItem();
	}
	
	private void rMinComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
		rMin = null;
		rMin = (String)rMinComboBox.getSelectedItem();
	}
	
	private void rTimeTypeComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
		rTimeType = null;
		rTimeType = (String)rTimeTypeComboBox.getSelectedItem();
		
	}
	
	private void rDateComboBoxActionPerformed(ActionEvent evt) {
		rDate = null;
		rDate = (String)rDateComboBox.getSelectedItem(); 
	}
	
	private void rMonthComboBoxActionPerformed(ActionEvent evt) {
		rMonth = null;
		rMonth = (String)rMonthComboBox.getSelectedItem();
	}
	
	private void rYearComboBoxActionPerformed(ActionEvent evt) {
		rYear = null;
		rYear = (String)rYearComboBox.getSelectedItem();
	}
	
    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {
    	
    	if(timeType == null)
    		timeType = "AM";
    	
    	if(rTimeType == null)
    		rTimeType = "AM";
    	
    	if(reminder == null)
    		reminder = "YES";
    	
        int save = JOptionPane.showConfirmDialog(this,"Are you sure you want to add? ","Add Entry",JOptionPane.YES_NO_OPTION);
        if(save == JOptionPane.YES_NO_OPTION){
            try{
            	String entryTime = null, reminderDate = null, reminderTime = null;
            	String entryCode = null;
            	int checkCode = 0, swapCode = 0;
            	
            	Statement stmt = con.createStatement();
            	ResultSet rset = stmt.executeQuery("SELECT * FROM ENTRY");
            	while(rset.next()) {
            		checkCode = rset.getInt(1);
            		if(swapCode < checkCode)
            			swapCode = checkCode;
            	}
            	stmt.close();
            	
            	if(timeType == null || timeType.equals("AM")) {
                	timeType = "AM";
                	if(hour.equals("12"))
                		hour = "00";
            	}
                else if(timeType.equals("PM"))
                	hour = Integer.toString(Integer.parseInt(hour) + 12);
                
            	if(reminder.equals("YES")) {
            		if(rTimeType == null || rTimeType.equals("AM")) {
            			rTimeType = "AM";
            			if(rHour.equals("12"))
            				rHour = "00";
            		}
            		else if(rTimeType.equals("PM")) {
            			if(Integer.parseInt(rHour) < 12)
            				rHour = Integer.toString(Integer.parseInt(rHour) + 12);
            		}
            	}
            	
            	
                entryTime = hour + min;
                reminderDate =  rYear + "-"  + rMonth+ "-" +rDate     ;
                reminderTime = rHour + ":" + rMin + ":00";
                String defaultDate = "2000-01-01", defaultTime = "00:00:00";
                
                java.util.Date entryDate = new java.util.Date(addEntryDate);
                
                entryCode = Integer.toString(swapCode + 1);
            	stmt = con.createStatement();
            	
            	if(reminder.equals("YES")) {
            		stmt.executeUpdate("INSERT INTO ENTRY VALUES (" +
            				Integer.parseInt(entryCode) + "," +
            				"'" + titleTextField.getText() 	+ "'," +
            				"'" + new java.sql.Date(entryDate.getTime()) 	+ "'," +
            				entryTime 				+ "," +
            				"'" + venueTextField.getText() 	+ "'," +
            				"'" + descriptionTextArea.getText() + "'," +
            				"'" + reminderDate 				+ "'," +
            				"'" + reminderTime 				+ "')");
            	}
            	else if (reminder.equals("NO")) {
            		stmt.executeUpdate("INSERT INTO ENTRY VALUES (" +
            				Integer.parseInt(entryCode) + "," +
            				"'" + titleTextField.getText() 	+ "'," +
            				"'" + new java.sql.Date(entryDate.getTime()) 	+ "'," +
            				entryTime 				+ "," +
            				"'" + venueTextField.getText() 	+ "'," +
            				"'" + descriptionTextArea.getText() + "'," +
            				"'" + defaultDate 				+ "'," +
            				"'" + defaultTime 				+ "')");
            	}
            	stmt.close();
            	
            	
            	//Delete all entry in the combo box
            	Edit.editTitleComboBox.removeAllItems();
            	DeleteEntry.deleteTitleComboBox.removeAllItems();
            	ViewEntry.viewTitleComboBox.removeAllItems();

            	//Add the entry into the other GUI combo box
            	stmt = con.createStatement();
            	rset = stmt.executeQuery("SELECT * FROM ENTRY WHERE E_DATE = '" + new java.sql.Date(entryDate.getTime()) + "' ORDER BY E_TITLE");
            	
            	int i = 1;
            	Edit.editTitleComboBox.insertItemAt(" ", 0);
            	DeleteEntry.deleteTitleComboBox.insertItemAt(" ", 0);
            	ViewEntry.viewTitleComboBox.insertItemAt(" ", 0);
            	while(rset.next()) {
            		Edit.editTitleComboBox.insertItemAt(rset.getString(2), i);
                	DeleteEntry.deleteTitleComboBox.insertItemAt(rset.getString(2), i);
                	ViewEntry.viewTitleComboBox.insertItemAt(rset.getString(2), i);
                	i++;
            	}
            	stmt.close();
            	
            	JOptionPane.showMessageDialog(this,titleTextField.getText() + " has been added.","Add Entry",JOptionPane.INFORMATION_MESSAGE);
            	
            	clearAllDetails();
            	choice = false;
            }
            catch(SQLException e){
                JOptionPane.showMessageDialog(this,"WARNING : "+ e.getMessage(),"Add Entry",JOptionPane.WARNING_MESSAGE);
            }
        }
    } 
    
    private void clearAllDetails() {
    	titleTextField.setText(null);
		venueTextField.setText(null);
		descriptionTextArea.setText(null);
		
		hourComboBox.setSelectedIndex(0);
		minComboBox.setSelectedIndex(0);
		timeTypeComboBox.setSelectedIndex(0);
		reminderComboBox.setSelectedIndex(0);
    	rHourComboBox.setSelectedIndex(0);
		rMinComboBox.setSelectedIndex(0);
		rTimeTypeComboBox.setSelectedIndex(0);
		rDateComboBox.setSelectedIndex(0);
		rMonthComboBox.setSelectedIndex(0);
		rYearComboBox.setSelectedIndex(0);
    }
    
    
    class PanelSwitchToEntryMenu implements ActionListener {
		public void actionPerformed(ActionEvent ae) {
			if(choice){
				int back = JOptionPane.showConfirmDialog(mainPanel,"Data are not saved. Are you sure you want to navigate from this page? ","Warning",JOptionPane.YES_NO_OPTION);
				if(back == JOptionPane.YES_NO_OPTION){
					clearAllDetails();
				}
			}
			choice = true;
			CardLayout c = (CardLayout)(mainPanel.getLayout());
			c.show(mainPanel, "EntryMenu");
		}
	}
    
    
    private javax.swing.JLabel addTitle;
    private javax.swing.JButton backButton;
    private javax.swing.JTextArea descriptionTextArea;
    private javax.swing.JComboBox hourComboBox;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JComboBox minComboBox;
    private javax.swing.JComboBox rDateComboBox;
    private javax.swing.JComboBox rHourComboBox;
    private javax.swing.JComboBox rMinComboBox;
    private javax.swing.JComboBox rMonthComboBox;
    private javax.swing.JComboBox rTimeTypeComboBox;
    private javax.swing.JComboBox rYearComboBox;
    private javax.swing.JComboBox reminderComboBox;
    private javax.swing.JButton saveButton;
    private javax.swing.JComboBox timeTypeComboBox;
    private javax.swing.JTextField titleTextField;
    private javax.swing.JTextField venueTextField;
}
